package com.smart.mapper;

import com.smart.pojo.Permission;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author lyj
 * @since 2023-04-19
 */
public interface PermissionMapper extends BaseMapper<Permission> {

    @Select("select p.*\n" +
            "from role_permission rp,permission p\n" +
            "where rp.permission_id=p.id\n" +
            "and rp.del_flag=0\n" +
            "and p.del_flag=0\n" +
            "and role_id=#{roleId}")
    List<Permission> queryByRoleId(Long roleId);

//    @Select("select distinct p.*\n" +
//            "from user u,\n" +
//            "role_permission rp,\n" +
//            "permission p\n" +
//            "where u.role_id=rp.role_id\n" +
//            "and rp.permission_id=p.id\n" +
//            "and u.del_flag=0\n" +
//            "and rp.del_flag=0\n" +
//            "and p.del_flag=0\n" +
//            "and u.id=#{userId}\n" +
//            "union\n" +
//            "select *\n" +
//            "from permission\n" +
//            "where is_public=1")
//    List<Permission> queryByUserId(Long userId);
    @Select("select distinct p.*\n" +
            "from user u,\n" +
            "role_permission rp,\n" +
            "permission p\n" +
            "where u.role_id=rp.role_id\n" +
            "and rp.permission_id=p.id\n" +
            "and u.del_flag=0\n" +
            "and rp.del_flag=0\n" +
            "and p.del_flag=0\n" +
            "and u.id=#{userId}")
    List<Permission> queryByUserId(Long userId);
}
